/* eslint-disable import/no-extraneous-dependencies */
const webpack = require('webpack');
// yarn add uglifyjs-webpack-plugin
// const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const TerserPlugin = require('terser-webpack-plugin');
const path = require('path');
const {
    // buildPath,
    curPath,
} = require('./buildSetting');

module.exports = {
    mode: 'production',
    entry: './src/index.js',
    output: {
        // path: path.resolve(buildPath),
        path: path.join(curPath, 'dist'),
        filename: 'main.js',
    },
    module: {
        rules: [
            {
                test: /(\.jsx|\.js)$/,
                use: {
                    loader: 'babel-loader',
                },
                exclude: /node_modules/,
            },
        ],
    },
    optimization: {
        minimizer: [
            new TerserPlugin({
                test: /\.js(\?.*)?$/i,  // 过滤文件
                extractComments: true,  // 去除所有的注释及说明
            }),
            // new UglifyJsPlugin({
            //     uglifyOptions: {
            //         warnings: false,
            //         output: {
            //             comments: true,
            //         },
            //     },
            // }),
        ],
    },
    plugins: [
        new webpack.ProvidePlugin({
            process: 'process',
            __dirname: '__dirname',
        }),
        new webpack.BannerPlugin('版权所有，翻版必究'),
        new webpack.optimize.OccurrenceOrderPlugin(),
        // new UglifyJsPlugin(),
    ],
};
